<template>
	<om-formsub-outer :index="index" :checkedit="checkedit">
		<om-autoform ref="autoform" :checkedit="checkedit" :initConfigData="autoformdata" :initValue="initValue"></om-autoform>
	</om-formsub-outer>
</template>

<script>
	import {buildSubFormData,subOnLoad, formValidation, changeEditor,configSelectData} from '../../../static/js/formUtil.js';
	import { ignoreHtml,ptFloat,minusF,sumF,errorModal, getDateStr, getDateTimeStr} from '@/static/js/common.js';
	import urlUtil from '@/static/js/urlUtil.js';
	export default {
		provide() {
			return {
				formPage: this
			};
		},
		data() {
			return buildSubFormData({
				initValue:{
					posId: "",
					instId: "",
					fileList:[],//上次保存的文件列表
				},
				formdata:{
					startTime: '',
					endTime: ''
				},
				businessformCacheKey:'fin-bx-expenses-data-info-businessform-cache',
				instCacheKey:'fin-bx-expenses-data-info-inst-cache',
				bxUserId:'',
				expenseCategoryId:'',
				expenseCategoryName:'',
				codeMap: {},
				dvid:'',
				instId: '',
				instName: '',
				feesAggregatedWayCodeCacheKey:'fin-bx-expenses-data-info-feesAggregatedWayCode-cache',
				researchDevelopmentIdCacheKey:'fin-bx-expenses-data-info-researchDevelopmentId-cache',
				businessOpportunityIdCacheKey:'fin-bx-expenses-data-info-businessOpportunityId-cache',
				saleOrderIdCacheKey:'fin-bx-expenses-data-info-saleOrderId-cache',
				newProductIdCacheKey:'fin-bx-expenses-data-info-newProductId-cache',
				addressCacheKey:'fin-bx-expenses-data-info-address-cache',
				sameOutUserCacheKey:'fin-bx-expenses-data-info-sameOutUser-cache',
				defaultDataCache:'fin-bx-expenses-data-info-defaultData-cache',
				feesAggregatedWayCache:'fin-bx-expenses-data-info-feesAggregatedWay-cache',
				partakeUserCache:'fin-bx-expenses-data-info-fpartakeUser-cache',
				marketingPlanningProductCache:'fin-bx-expenses-data-info-marketingPlanningProduct-cache',
				setDataCacheKey:'fin-bx-travels-setData-cache',
				expenseTypeSysId:'',
				erpProjectBatches:'',
				checkedit:false
			})
		},
		watch:{
			'formdata.applyPayNum':function(newVal,oldVal){
				let _that = this
				if(!_that.checkedit){
					_that.$refs.autoform.formdata.sumCosts = newVal
				}
			}
		},
		methods: {
			clearCity(){
				let _that = this
				let formdata = _that.$refs.autoform.formdata
				_that.$refs.autoform.clear("title2","cityId")
				_that.getReimbursedBasedExpensePerson('',_that.expenseTypeSysId)
			},
			onSelectCity(item){
				let _that = this
				_that.getReimbursedBasedExpensePerson(item.id,_that.expenseTypeSysId)
				_that.$refs.autoform.formdata.cityId = item.id
				_that.$refs.autoform.formdata.cityName = item.dicname
				for(let data of _that.datas){
					if(data.cityId == item.id){
						_that.$refs.autoform.formdata.startTime = data.startTime
						_that.$refs.autoform.formdata.endTime = data.endTime
						_that.$refs.autoform.formdata.address = data.address
						_that.$refs.autoform.formdata.remark = data.remark
						_that.$refs.autoform.formdata.vehicleTypeCode = data.vehicleTypeCode
						_that.$refs.autoform.formdata.vehicleTypeName = data.vehicleTypeName
						_that.$refs.autoform.initSelectIndex("title2","vehicleTypeCode")
						_that.$refs.autoform.formdata.sameOutUserId = data.sameOutUserId
						_that.$refs.autoform.formdata.sameOutUserName = data.sameOutUserName
						_that.$refs.autoform.formdata.partakeInstId = data.partakeInstId
						_that.$refs.autoform.formdata.partakeInstName = data.partakeInstName
					}
				}
			},
			onSelectPartakeInst(id){
				let _that = this
			},
			verifyPartakeUser(){
				let _that = this
				if(!_that.$refs.autoform.formdata.partakeInstId){
					let title1 = _that.$refs.autoform.getEditorTitle("title2")
					let title2 = _that.$refs.autoform.getEditorTitle("title2","partakeInstId")
					errorModal(_that,'提示信息',title1+'的'+title2+'需要优先完成编辑!',()=>{
						return false
					})
				}else{
					_that.$refs.autoform.changeEditor("title2","partakeUserId",{
						"link":'../../public/search/search',
						"linkParam":{
							other:JSON.stringify({
								instId:_that.$refs.autoform.formdata.partakeInstId
							}),
							url:'orgInstPosUserOfficial/getUserListByInstPosId',
							initload:true,
							namefield:'username',
							cachename:_that.partakeUserCache
						}
					})
					return true
				}
			},
			getReimbursedBasedExpensePerson(id,expenseTypeId){
				let _that = this
				let formdata = _that.$refs.autoform.formdata
				_that.om.request(
					"reimbursementCriteria/getReimbursedBasedExpensePerson",
					{
						expenseTypeId:expenseTypeId,
						userId: _that.bxUserId,
						cityId: id,
					}
				).then(res=>{
					_that.$refs.autoform.formdata.reimbursementCriteriaId = res.value.reimbursementCriteriaId
					_that.$refs.autoform.formdata.reimbursementStandardId = res.value.reimbursementStandardId
					if(res.value.reimbursementStandards){
						_that.$refs.autoform.formdata.reimbursementStandards = res.value.reimbursementStandards
						if(formdata.startTime && formdata.endTime && (formdata.startTime!=formdata.endTime)){
							_that.getDayNumFunc(formdata.startTime,formdata.endTime)
						}
					}else{
						_that.$refs.autoform.clear("title2","reimbursementStandardId")
						_that.$refs.autoform.clear("title2","calculateAmount")
						_that.$refs.autoform.clear("title2","applyPayNum")
					}
				})
			},
			clearFeesAggregatedWayCode(){
				let _that = this
				_that.$refs.autoform.clear('title2', 'feesAggregatedWayCode');
				_that.$refs.autoform.changeEditor("title2", "partakeUserId", "required", false)
			},
			clearPartakeInstId(){
				let _that = this
				_that.$refs.autoform.clear('title2', 'partakeInstId');
				_that.$refs.autoform.clear('title2', 'feesAggregatedWayCode');
				_that.$refs.autoform.changeEditor("title2", "feesAggregatedWayCode","type","labelbox")
				_that.$refs.autoform.changeEditor("title2", "partakeUserId", "required", false)
			},
			clearResearchDevelopmentId(){
				let _that = this
				_that.$refs.autoform.clear('title2', 'researchDevelopmentId');
				_that.$refs.autoform.clear('title2', 'researchDevelopmentCode');
			},
			clearBusinessOpportunityId(){
				let _that = this
				_that.$refs.autoform.clear('title2', 'businessOpportunityId');
				_that.$refs.autoform.clear('title2', 'businessOpportunityCode');
			},
			onSelectGetExpenseByParent(item){
				let _that = this
				let formdata = _that.$refs.autoform.formdata
				formdata.expenseTypeId = item.id
				_that.expenseTypeSysId = item.expenseTypeId
				_that.getReimbursedBasedExpensePerson(formdata.cityId?formdata.cityId:'',item.expenseTypeId)
				formdata.expenseTypeName = item.typeName
				formdata.expenseTypeCode = item.typeCode
				formdata.expenseCategoryId = _that.expenseCategoryId
				formdata.expenseCategoryName = _that.expenseCategoryName
				_that.om.request('expenseCategory/getLevel1AccountDictByExpense', {
					expenseCategoryId: item.id					
				}).then(res => {
					if(res.succeed){
						formdata.levelOneAccountId = res.value.id
						formdata.levelOneAccountName = res.value.dicname
						formdata.levelOneAccountCode = res.value.code
					}
				});
				_that.om.request('expenseCategory/getAccountByExpensePosition', {
					expenseCategoryId: item.id,
					postId: '',
				}).then(res => {
					if(res.succeed){
						formdata.budgetLevelOneAccountId = res.value.budgetAccountDictId
						formdata.budgetLevelOneAccountName = res.value.budgetAccountDictName
						formdata.budgetLevelTwoAccountId = res.value.budgetSubAccountDictId
						formdata.budgetLevelTwoAccountName = res.value.budgetSubAccountDictName
					}
				});
			},
			clearGetExpenseByParent(){
				let _that = this
				_that.$refs.autoform.clear('title2', 'expenseTypeId');
				_that.$refs.autoform.clear('title2', 'expenseTypeCode');
				_that.$refs.autoform.clear('title2', 'expenseCategoryId');
				_that.$refs.autoform.clear('title2', 'levelOneAccountId');
				_that.$refs.autoform.clear('title2', 'levelOneAccountCode');
				_that.$refs.autoform.clear('title2', 'budgetLevelOneAccountId');
				_that.$refs.autoform.clear('title2', 'budgetLevelTwoAccountName');
				_that.$refs.autoform.clear("title2","reimbursementStandardId")
				_that.$refs.autoform.clear("title2","calculateAmount")
				_that.$refs.autoform.clear("title2","applyPayNum")
				_that.$refs.autoform.clear("title2","startTime")
				_that.$refs.autoform.clear("title2","endTime")
			},
			clearBusinessTravel(){
				let formdata = this.$refs.autoform.formdata
				formdata.businessTravelId = "";
				formdata.businessTravelDataId = "";
				formdata.businessTravelCode = "";
				formdata.planStartTime = "";
				formdata.planEndTime = "";
				formdata.startTime = "";
				formdata.endTime = "";
				formdata.cityName = "";
				formdata.address = "";
				formdata.remark = "";
				formdata.sumCosts = "";
				formdata.companions = "";
				formdata.voucherNum = "";
				formdata.taxRate = "";
				formdata.partakeInstId = "";
				formdata.partakeInstName = "";
				formdata.dayNum = "";
				formdata.invoiceNumber = "";
				formdata.vehicleTypeCode = "";
				formdata.vehicleTypeName = "";
			},
			onSelectAccount(account){
				this.$refs.autoform.formdata.accountCode = account.code;
				if(account.layerNum == 1) {
					this.$refs.autoform.formdata.accountParentId = account.id;
					this.$refs.autoform.formdata.accountParentName = account.dicname;
				}else{
					let _that = this
					_that.om.request("accountDict/findLevel1Account",{
						accountDictId: account.id
					}).then(res=>{
						if(res.succeed){
							var value = res.value
							_that.$refs.autoform.formdata.accountParentId = value.id;
							_that.$refs.autoform.formdata.accountParentName = value.dicname;
						}else{
							_that.om.toast(res.msg)
						}
					})
				}
			},
			clearAccount(){
				var formdata = this.$refs.autoform.formdata
				this.$refs.autoform.clear("title2", "accountId")					
				formdata.accountCode = ""
				formdata.accountParentId = ""
				formdata.accountParentName = ""
			},
			onSelectStartTime(startTime){
				let _that = this
				let currentTime = getDateTimeStr(new Date())
				let endTime = _that.$refs.autoform.formdata.endTime || currentTime
				if(startTime > endTime){
					_that.om.toast("开始时间不大于当前时间和结束时间")
					_that.$refs.autoform.formdata.startTime = ''
					_that.$refs.autoform.formdata.dayNum = ''
				}
				if(_that.$refs.autoform.formdata.startTime && endTime){
					_that.getDayNumFunc(startTime, endTime)
				}
			},
			onSelectEndTime(endTime){
				let _that = this
				let currentTime = getDateTimeStr(new Date())
				let startTime = _that.$refs.autoform.formdata.startTime
				if(startTime){
					if(endTime < startTime){
						_that.om.toast("结束时间不小于开始时间")
						_that.$refs.autoform.formdata.endTime = ''
						_that.$refs.autoform.formdata.dayNum = ''
					}else{
						_that.getDayNumFunc(startTime, endTime)
					}
				}else{
					_that.getDayNumFunc(startTime, endTime)
				}
			},
			getDayNumFunc(startDate, endDate){
				let _that = this
				_that.om.request('common/getGoOutWorkDayNum', {
					startDate: startDate,
					endDate: endDate,
				}).then(res => {
					if(res.succeed){
						_that.$refs.autoform.formdata.dayNum = res.value
						if(_that.$refs.autoform.formdata.reimbursementStandards){
							let dayNum = Number(_that.$refs.autoform.formdata.dayNum)
							let reimbursementStandards = Number(_that.$refs.autoform.formdata.reimbursementStandards)
							_that.$refs.autoform.formdata.calculateAmount = dayNum*reimbursementStandards
							_that.$refs.autoform.formdata.applyPayNum = dayNum*reimbursementStandards
							_that.$refs.autoform.formdata.sumCosts = dayNum*reimbursementStandards
						}
					}
				});
			},
			verifyStartTime(datetime){
				var currentTime = getDateStr(new Date())
				var endTime = this.formdata.endTime || currentTime
				
				if(datetime > endTime){
					return "开始时间不大于当前时间和结束时间"
				}else{
					return true
				}
				
			},
			verifyEndTime(datetime){
				var currentTime = getDateStr(new Date())
				var startime = this.formdata.startTime
				
				if(startime){
					if(datetime < startime){
						return "结束时间不小于开始时间"
					}else if(datetime > currentTime){
						return "结束时间不大于当前时间"
					}else{
						return true
					}
				}else if(datetime > currentTime){
					return "结束时间不大于当前时间"
				}else{
					return true
				}
			},
			initLoad(){
				let _that = this
				//费用类型
				_that.om.request('expenseCategory/getExpenseByParent', {
					id: _that.expenseCategoryId					
				}).then(res => {
					_that.$refs.autoform.changeEditor("title2", "expenseTypeId", "data", configSelectData(res,"id","typeName"))
					_that.$refs.autoform.initSelectIndex("title2", "expenseTypeId")
					if(_that.formdata.expenseTypeId){
						for(let item of res){
							if(item.id == _that.formdata.expenseTypeId){
								_that.expenseTypeSysId = item.expenseTypeId
							}
						}
					}
				});
				
				//会计科目
				_that.om.request('accountDict/getCombobox', {
					selectInBudget: true					
				}).then(res => {
					_that.$refs.autoform.changeEditor("title2", "accountId", "data", configSelectData(res,"id","dicname"))
					_that.$refs.autoform.initSelectIndex("title2", "accountId")
				});
				
				//交通工具
				_that.om.request('dictZero/getCombobox', {
					code: "37373"					
				}).then(res => {
					_that.$refs.autoform.changeEditor("title2", "vehicleTypeCode", "data", configSelectData(res, "code", "dicname"))
					_that.$refs.autoform.initSelectIndex("title2", "vehicleTypeCode")
				});
				
				//产品线类别
				// _that.om.request('inventoryCategory/getExistingProductLineAssortment', {}).then(res => {
				// 	_that.$refs.autoform.changeEditor("title2", "marketingPlanningProductId", "data", configSelectData(res,"id","name"))
				// 	_that.$refs.autoform.initSelectIndex("title2", "marketingPlanningProductId")
				// });
				
				_that.$nextTick(function(){
					//承担人
					_that.om.request('orgInstPosUserOfficial/getUserListByInstPosId', {
						instId: _that.$refs.autoform.formdata.partakeInstId || _that.instId					
					}).then(res => {
						_that.$refs.autoform.changeEditor("title2", "partakeUserId", "data", configSelectData(res,"id","username"))
						_that.$refs.autoform.initSelectIndex("title2", "partakeUserId")
					});
					
					_that.$refs.autoform.initDataTime("title2", "startTime")
					_that.$refs.autoform.initDataTime("title2", "endTime")
				})
			}
		},
		onLoad(e){
			let _that = this
			subOnLoad(_that, e, function() {
				_that.bxUserId = e.bxUserId
				_that.instId = e.instId
				_that.instName = e.instName
				if(e.edit == 'true'){
					_that.edit = true
				}
				// _that.initValue.partakeInstId = e.instId
				// _that.initValue.partakeInstName = e.instName
				_that.expenseCategoryId = e.expenseCategoryId
				_that.expenseCategoryName = e.expenseCategoryName
				_that.codeMap = JSON.parse(e.codeMap) 
				_that.dvid = e.dvid
				_that.erpProjectBatches = e.erpProjectBatches
				if(e.checkedit == 'true'){
					_that.checkedit = true
				}
				if(e.bxUserId && e.configDataCacheKey){
					uni.getStorage({
						key: e.configDataCacheKey,
						success: function(res) {
							//if(res.data && res.data instanceof Array){
							if(res.data && Object.prototype.toString.call(res.data)==='[object Array]'){
								_that.autoformdata = res.data
								Object.assign(_that.initValue, _that.formdata)
								_that.autoformdata[0].order = _that.order
								changeEditor(_that.autoformdata[0].editors,"startTime","noInitDate",true)
								changeEditor(_that.autoformdata[0].editors,"endTime","noInitDate",true)
								changeEditor(_that.autoformdata[0].editors,"feesAggregatedWayCode",{
									"linkParam":{
										other:JSON.stringify({
											code: _that.codeMap.feesAggregatedWayCode
										}),
										url:"tsysdict/getCombobox",
										cachename:_that.feesAggregatedWayCodeCacheKey,
										initload:true,
										namefield:'dicname'
									}
								})
								changeEditor(_that.autoformdata[0].editors, "partakeInstId","link","../../public/search/search")
								changeEditor(_that.autoformdata[0].editors, "partakeInstId", "linkParam", {
									method:"post",
									namefield:"instname",
									searchfield:"instName",
									initload:true,
									url:"tinstitution/findNotBoard1",
									cachename:_that.instCacheKey,
									placeholder:"请输入机构名称"
								})
								changeEditor(_that.autoformdata[0].editors, "businessTravelDataId","link","../../public/pageSearch/pageSearch")
								changeEditor(_that.autoformdata[0].editors, "businessTravelDataId", "linkParam", {
									other:JSON.stringify({
										userId: _that.bxUserId,
										travelExpensesId: _that.dvid,
									}),
									namefield:"businessTravelCode",
									notefield:"cityName|address",
									// extrafield:"planStartTime~planEndTime",
									// extrasplit:"~",
									searchfield:"q",
									initload:true,
									url:"travelExpenses/getBusinessLeaveList",
									cachename:_that.businessformCacheKey,
									placeholder:"请输入关键字查询",
									method:'post'
								})
								changeEditor(_that.autoformdata[0].editors, "researchDevelopmentId","link","../../public/pageSearch/pageSearch")
								changeEditor(_that.autoformdata[0].editors, "researchDevelopmentId", "linkParam", {
									namefield:"projectName",
									notefield:"projectCode",
									extrafield:"typeName",
									searchfield:"q",
									initload:true,
									url:"createProjectShow/findCreateProjectShowPage",
									cachename:_that.researchDevelopmentIdCacheKey,
									placeholder:"请输入关键字查询",
								})
								changeEditor(_that.autoformdata[0].editors, "businessOpportunityId","link","../../public/pageSearch/pageSearch")
								changeEditor(_that.autoformdata[0].editors, "businessOpportunityId", "linkParam", {
									namefield:"biddingProjectName",
									notefield:"biddingCode",
									searchfield:"q",
									initload:true,
									url:"biddingProject/getBidding",
									cachename:_that.businessOpportunityIdCacheKey,
									placeholder:"请输入关键字查询",
								})
								changeEditor(_that.autoformdata[0].editors, "saleOrderId","link","../../public/pageSearch/pageSearch")
								changeEditor(_that.autoformdata[0].editors, "saleOrderId", "linkParam", {
									namefield:"customerRequirementCode",
									notefield:"customerNameX",
									searchfield:"search",
									initload:true,
									url:"customerRequirementShow/getHeaderDataToDelivery",
									cachename:_that.saleOrderIdCacheKey,
									placeholder:"请输入关键字查询",
								})
								changeEditor(_that.autoformdata[0].editors, "newProductId","link","../../public/pageSearch/pageSearch")
								changeEditor(_that.autoformdata[0].editors, "newProductId", "linkParam", {
									namefield:"newProductName",
									notefield:"newProductStd",
									searchfield:"q",
									initload:true,
									url:"productShowSecond/getProductPage",
									cachename:_that.newProductIdCacheKey,
									placeholder:"请输入关键字查询",
								})
								changeEditor("title2","marketingPlanningProductId",{
									"link":'../../public/search/search',
									"linkParam":{
										other:JSON.stringify({
											firstId:''
										}),
										url:'inventoryCategory/getExistingProductLineAssortment',
										namefield:'name',
										initload:true,
										cachename:_that.marketingPlanningProductCache
									}
								},null,_that.autoformdata)
								// changeEditor(_that.autoformdata[0].editors, "startTime","endField","endTime")
								// changeEditor(_that.autoformdata[0].editors, "endTime","startField","startTime")
								// changeEditor(_that.autoformdata[0].editors, "endTime","max", getDateStr(new Date()))
								changeEditor(_that.autoformdata[0].editors, "fileList", "fileUploadKey", "127")
								if(_that.formdata.fileList) {
									var tempFileList = []
									var fileUrlList = _that.formdata.fileList.map(t=>{
										tempFileList.push(t.fileSaveName)
										return t.fileSaveName
									})
									changeEditor(_that.autoformdata[0].editors, "fileList", "fileUrlList", fileUrlList)
									changeEditor(_that.autoformdata[0].editors, "fileList", "tempFileList", tempFileList)
								}
								changeEditor("title2", 'cityId','type','areabox',_that.autoformdata)
								changeEditor("title2", 'cityId', {
									link:'../../public/pageSearch/pageSearch',
									'linkParam':{
										other: JSON.stringify({
											classifyCode: '37056'
										}),
										searchfield: 'q',
										namefield: 'dicname',
										url: urlUtil.addressUrl().url,
										cachename: _that.addressCacheKey,
										placeholder: '请输入地址',
									}
								},null,_that.autoformdata)
								changeEditor('title2', 'sameOutUserId', {
									'link':'../../public/searchUser/searchUser',
									linkParam: {
										namefield: urlUtil.userPageUrl().namefield,
										searchfield: "q",
										defaultDataCache:_that.defaultDataCache,
										cachename: _that.sameOutUserCacheKey,
										isNew:true,
										placeholder: urlUtil.userPageUrl().prompt,
										pagination: true
									}
								}, null, _that.autoformdata);
								changeEditor("title2","feesAggregatedWayIds",{
									"linkParam":{
										other:JSON.stringify({
											code:'40346'
										}),
										url:'tsysdict/getComboTree',
										namefield:'text',
										initload:true,
										cachename:_that.feesAggregatedWayCache
									}
								},null,_that.autoformdata)
								
								if(_that.formdata.sameOutUserId){
									let idArr = _that.formdata.sameOutUserId.split(",")
									let nameArr = _that.formdata.sameOutUserName.split(",")
									let userList = []
									for(let index in idArr){
										let obj = {
											id:idArr[index],
											username:nameArr[index]
										}
										userList.push(obj)
									}
									uni.setStorage({
										key:_that.defaultDataCache,
										data:userList
									})
								}
								if(!_that.formdata.partakeInstId){
									uni.getStorage({
										key:_that.setDataCacheKey,
										success:(res)=>{
											if(res.data){
												let d = res.data
												changeEditor('title2', 'partakeInstId', {
													defaultName:d.partakeInstName,
													defaultValue:d.partakeInstId 
												},null,_that.autoformdata)
											}
										},
									})
								}
								if(!_that.formdata.erpProjectBatches){
									changeEditor('title2', 'erpProjectBatches', {
										defaultName:_that.erpProjectBatches,
										defaultValue:_that.erpProjectBatches 
									},null,_that.autoformdata)
								}
								if(_that.formdata.feesAggregatedWayIds){
									let fawiArr = _that.formdata.feesAggregatedWayIds.split(",")
									let fawnArr = _that.formdata.feesAggregatedWayName.split(",")
									let feesAggregatedWayList = []
									for(let index in fawiArr){
										let obj = {
											id:fawiArr[index],
											text:fawnArr[index]
										}
										feesAggregatedWayList.push(obj)
									}
									changeEditor('title2', 'feesAggregatedWayIds', {
										initSelect: feesAggregatedWayList
									},null,_that.autoformdata)
								}else{
									uni.getStorage({
										key:_that.setDataCacheKey,
										success:(res)=>{
											if(res.data){
												let d = res.data
												let idArr = d.feesAggregatedWayIds.split(",")
												let nameArr = d.feesAggregatedWayName.split(",")
												let feesAggregatedWayList = []
												for(let index in idArr){
													let obj = {
														id:idArr[index],
														text:nameArr[index]
													}
													feesAggregatedWayList.push(obj)
												}
												changeEditor('title2', 'feesAggregatedWayIds', {
													initSelect: feesAggregatedWayList
												},null,_that.autoformdata)
												changeEditor('title2', 'feesAggregatedWayIds', {
													defaultName:d.feesAggregatedWayName,
													defaultValue: d.feesAggregatedWayIds
												},null,_that.autoformdata)
											}
										}
									})
								}
								_that.initLoad()
								_that.$nextTick(function(){
									if(_that.$refs.autoform.formdata.feesAggregatedWayCode){
										let objArr = []
										let ids = _that.$refs.autoform.formdata.feesAggregatedWayCode.split(",")
										let names = _that.$refs.autoform.formdata.feesAggregatedWayName.split(",")
										for(let index in ids){
											let obj = {
												code:ids[index],
												dicname:names[index]
											}
											objArr.push(obj)
										}
										_that.$refs.autoform.changeEditor("title2", "feesAggregatedWayCode","type","multilinkbox")
										_that.$refs.autoform.changeEditor('title2', 'feesAggregatedWayCode', {
											initSelect: objArr
										})
										if(ids.indexOf('40392') > -1){
											_that.$refs.autoform.changeEditor("title2", "partakeUserId", "required", true)
										}else{
											_that.$refs.autoform.changeEditor("title2", "partakeUserId", "required", false)
										}
									}else{
										_that.$refs.autoform.changeEditor("title2", "feesAggregatedWayCode","type","labelbox")
										_that.$refs.autoform.changeEditor("title2", "partakeUserId", "required", false)
									}
								})
							}
						}
					});
				}
			})
		},
		onUnload(){
			let _that = this
			uni.removeStorage({
				key:_that.defaultDataCache
			})
			
		},
		onShow() {
			let _that = this
			if(_that.$refs.autoform){
				uni.getStorage({
					key: _that.instCacheKey,
					success: function(res) {
						if(res.data){
							let d = res.data
							var formdata  = _that.$refs.autoform.formdata
							formdata.partakeInstId = d.id
							formdata.partakeInstName = d.instname
							_that.instId = d.id
							_that.onSelectPartakeInst(d.id)
							if(_that.$refs.autoform.formdata.partakeUserId){
								_that.$refs.autoform.clear("title1","partakeUserId")
							}
							_that.om.request('orgInstPosUserOfficial/getUserListByInstPosId', {
								instId: _that.instId					
							}).then(res => {
								_that.$refs.autoform.changeEditor("title2", "partakeUserId", "data", configSelectData(res,"id","username"))
								_that.$refs.autoform.initSelectIndex("title2", "partakeUserId")
							});
							_that.$refs.autoform.changeEditor("title2", "feesAggregatedWayCode","type","multilinkbox")
							uni.removeStorage({
								key: _that.instCacheKey
							});
						}
					}
				});
				uni.getStorage({
					key:_that.partakeUserCache,
					success:(res)=>{
						if(res.data){
							let d = res.data
							let formdata = _that.$refs.autoform.formdata
							formdata.partakeUserId = d.id
							formdata.partakeUserName = d.username
						}
						uni.removeStorage({
							key:_that.partakeUserCache
						})
					}
				})
				uni.getStorage({
					key: _that.businessformCacheKey,
					success: function(res) {
						if(res.data){
							let d = res.data
							var formdata  = _that.$refs.autoform.formdata
							formdata.businessTravelId = d.businessTravelId;
							formdata.businessTravelDataId = d.businessTravelDataId;
							formdata.businessTravelCode = d.businessTravelCode;
							formdata.planStartTime = d.planStartTime;
							formdata.planEndTime = d.planEndTime;
							formdata.startTime = d.planStartTime;
							formdata.endTime = d.endTime;
							formdata.cityName = d.cityName;
							formdata.address = d.address;
							formdata.vehicleTypeCode = d.vehicleTypeCode;
							formdata.vehicleTypeName = d.vehicleTypeName;
							_that.$refs.autoform.initSelectIndex("title2", "vehicleTypeCode")
							formdata.partakeInstId = _that.instId;
							formdata.partakeInstName = _that.instName;
							if(_that.instId){
								_that.$refs.autoform.changeEditor("title2", "feesAggregatedWayCode","type","multilinkbox")
							}else{
								_that.$refs.autoform.changeEditor("title2", "feesAggregatedWayCode","type","labelbox")
							}
							_that.$nextTick(function(){
								_that.$refs.autoform.initDataTime("title2", "startTime")
								_that.$refs.autoform.initDataTime("title2", "endTime")
							})
							uni.removeStorage({
								key: _that.businessformCacheKey
							});
						}
					}
				});
				uni.getStorage({
					key: _that.feesAggregatedWayCodeCacheKey,
					success: function(res) {
						if(res.data){
							let d = res.data
							var formdata  = _that.$refs.autoform.formdata
							formdata.feesAggregatedWayCode = d.map(e=>e.code).join(',')
							formdata.feesAggregatedWayName = d.map(e=>e.dicname).join(',')
							_that.$refs.autoform.changeEditor('title2', 'feesAggregatedWayCode', {
								initSelect: d
							})
							let sz = formdata.feesAggregatedWayCode.split(',')
							if(sz.indexOf('40392') > -1){
								_that.$refs.autoform.changeEditor("title2", "partakeUserId", "required", true)
							}else{
								_that.$refs.autoform.changeEditor("title2", "partakeUserId", "required", false)
							}
							
							uni.removeStorage({
								key: _that.feesAggregatedWayCodeCacheKey
							});
						}
					}
				});
				uni.getStorage({
					key: _that.researchDevelopmentIdCacheKey,
					success: function(res) {
						if(res.data){
							let d = res.data
							var formdata  = _that.$refs.autoform.formdata
							formdata.researchDevelopmentId = d.id
							formdata.researchDevelopmentName = d.projectName
							formdata.researchDevelopmentCode = d.projectCode
							uni.removeStorage({
								key: _that.researchDevelopmentIdCacheKey
							});
						}
					}
				});
				uni.getStorage({
					key: _that.businessOpportunityIdCacheKey,
					success: function(res) {
						if(res.data){
							let d = res.data
							var formdata  = _that.$refs.autoform.formdata
							formdata.businessOpportunityId = d.id
							formdata.businessOpportunityName = d.biddingProjectName
							formdata.businessOpportunityCode = d.biddingCode
							uni.removeStorage({
								key: _that.businessOpportunityIdCacheKey
							});
						}
					}
				});
				uni.getStorage({
					key: _that.saleOrderIdCacheKey,
					success: function(res) {
						if(res.data){
							let d = res.data
							var formdata  = _that.$refs.autoform.formdata
							formdata.saleOrderId = d.customerRequirementId
							formdata.saleOrderCode = d.customerRequirementCode
							uni.removeStorage({
								key: _that.saleOrderIdCacheKey
							});
						}
					}
				});
				uni.getStorage({
					key: _that.newProductIdCacheKey,
					success: function(res) {
						if(res.data){
							let d = res.data
							var formdata  = _that.$refs.autoform.formdata
							formdata.newProductId = d.id
							formdata.newProductCode = d.newProductCode
							uni.removeStorage({
								key: _that.newProductIdCacheKey
							});
						}
					}
				});
				uni.getStorage({
					key: _that.addressCacheKey,
					success: function(res) {
						if (res.data) {
							let d = res.data;
							var formdata = _that.$refs.autoform.formdata;
							_that.$refs.autoform.$refs.areapop.close()
							_that.onSelectCity(d)
							if(formdata.expenseTypeId){
								_that.getReimbursedBasedExpensePerson(d.id,formdata.expenseTypeId)
							}
							uni.removeStorage({
								key: _that.addressCacheKey
							});
						}
					}
				});
				uni.getStorage({
					key: _that.sameOutUserCacheKey,
					success: function(res) {
						if (res.data) {
							let d = res.data;
							uni.setStorage({
								key:_that.defaultDataCache,
								data:d
							})
							var formdata = _that.$refs.autoform.formdata;
							let idList = []
							let nameList = []
							let sameOutUserId = ''
							if(formdata.sameOutUserId){
								sameOutUserId = formdata.sameOutUserId.split(',')
							}
							for(let index in d){
								idList.push(d[index].id)
								nameList.push(d[index].username)
							}
							let idStr = idList.map(e =>e).join(",")
							let nameStr = nameList.map(e =>e).join(",");
							formdata.sameOutUserId = idStr
							formdata.sameOutUserName = nameStr
							uni.removeStorage({
								key: _that.sameOutUserCacheKey
							});
						}
					}
				});
				uni.getStorage({
					key: _that.feesAggregatedWayCache, //费用承担机构
					success: function(res) {
						if(res.data){
							let d = res.data
							var formdata  = _that.$refs.autoform.formdata
							formdata.feesAggregatedWayIds = d.map(e=> e.id).join(',')
							formdata.feesAggregatedWayName = d.map(e=> e.text).join(',')
							_that.$refs.autoform.changeEditor('title2', 'feesAggregatedWayIds', {
								initSelect: d
							})
							uni.removeStorage({
								key: _that.feesAggregatedWayCache
							});
						}
					}
				});
				uni.getStorage({
					key:_that.marketingPlanningProductCache,
					success:(res)=>{
						if(res.data){
							let d = res.data
							let formdata = _that.$refs.autoform.formdata
							formdata.marketingPlanningProductId = d.id
							formdata.marketingPlanningProductName = d.name
						}
						uni.removeStorage({
							key:_that.marketingPlanningProductCache
						})
					}
				})
			}
		}
	}
</script>

<style>

</style>